#include <my_head.h>
int main(int argc, char const *argv[])
{
    pid_t pid = fork();
    if(-1 == pid){
        ERR_LOG("fork error");
    }else if(0<pid){
        exit(EXIT_SUCCESS);
    }else if(0 == pid){
        if(-1 == setsid()){
            ERR_LOG("setsid error");
        }
        if(-1 == chdir("/")){
            ERR_LOG("chdir error");
        }
        umask(0066);
        for(i = 3;i<1024;i++){
            close(i);
        }
        int fd = open("xy.log",O_WRONLY|O_CREAT|O_TRUNC,0664);
        if(-1 == open)
            ERR_LOG("open error");
        dup2(fd,0);
        dup2(fd,1);
        dup2(fd,2);
        int i = 0;
        while(1){
            printf("xxx %d\n",++i);
            fflush(stdout);
            sleep(1);
        }
          close(fd);
    }
    return 0;
}
